/* ==============================================================================
 * 创 建 者：lyt
 * 创建日期：2017-07-14	
 * 功能描述：商品分类

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/
//修改密码
var editPasswordUrl = baseUrl+'MemberF/EditMemberLoginPwd';
//获取手机验证码
var getCodeUrl =  baseUrl+'MemberF/SendEditMemberPwdCode';
//会员信息获取
var getMemberViewUrl = baseUrl + 'MemberF/MemberView';

var vu;
$(function(){
	initVue();
});

function initVue(){
	vu = new Vue({
		el : '#content',
		data : {
		    oldPwd: '',
			newPwd : '',
			confirmPwd : '',//确认密码
			DefaultCoin : '',
			member : '',
			validCode:true,
			VerificationCode:''
		},
		mounted: function() {
			this.getMemberView();
		},
		methods : {
			getMemberView : getMemberView,
			editPassword : function(){
			    if (!this.VerificationCode) {
					mui.toast('请输入验证码！');
					return ;
				}
				if(!this.newPwd){
					mui.toast('请输入新密码！');
					return ;
				}
				if(!this.confirmPwd){
					mui.toast('请再次输入新密码！');
					return ;
				}
				if(this.newPwd != this.confirmPwd){
					mui.toast('两次密码不一致，请重新输入！');
					return ;
				}
				var data = {
					VerificationCode : this.VerificationCode,
					NewPassword : this.newPwd,
					ConNewPassword : this.confirmPwd,
				};
				common.post(editPasswordUrl,data,'json',function(r){
					if(r.ErrorCode==0){
						mui.toast('修改成功');
						vu.VerificationCode = '';
						vu.newPwd = '';
						vu.confirmPwd = '';
//						location.href='index.html'
					}else{
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getCode : function(e) {
				var _this = this;
				var code = $(e.target);
				var time = 60;
				common.post(getCodeUrl, {}, 'json', function(r) {
					if(r.ErrorCode == 0) {
						if(_this.validCode) {
							_this.validCode = false;
							if(r.Data.RemainingTime){
								time = r.Data.RemainingTime;
							}
							var t = setInterval(function() {
								time--;
								code.text(time + "秒");
								if(time == 0) {
									clearInterval(t);
									code.text("获取验证码");
									_this.validCode = true;
								}
							}, 1000)
						}
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
		}
	})
}

function getMemberView(){
	common.get(getMemberViewUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.member = r.Data.member;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}